cmake_minimum_required(VERSION 3.11 FATAL_ERROR)
project(rk3588-demo VERSION 0.0.1)
message(STATUS "System: ${CMAKE_SYSTEM_NAME} ${CMAKE_SYSTEM_VERSION}")

# addrstrace
# option(ENABLE_ASAN "Enable AddressSanitizer" ON)
# if(ENABLE_ASAN)
#     message(STATUS "AddressSanitizer 已启用")
#     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fsanitize=address -fno-omit-frame-pointer")
#     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=address -fno-omit-frame-pointer")
#     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
# else()
#     message(STATUS "AddressSanitizer 未启用")
# endif()

#编译器
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

#库架构
set(LIB_ARCH "aarch64")
set(DEVICE_NAME "RK3588")
# 第三方库根目录（module-ffmpeg）
set(THREERD_MODULE_FFMPEG ${CMAKE_CURRENT_LIST_DIR}/ffmpeg-rockchip)
# ============================ FFmpeg 配置 ============================
# 1. 头文件路径（实际头文件在 ffmpeg/include 下）
set(FFMPEG_INCLUDE_DIRS 
    SYSTEM 
    ${THREERD_MODULE_FFMPEG}/include  # 修正：指向实际头文件目录
    /usr/local/ffmpeg/include  # 保留系统目录（如有必要）
)
# 2. 库文件路径（实际库在 ffmpeg/lib 下）
set(FFMPEG_LIB_DIRS 
    ${THREERD_MODULE_FFMPEG}/lib  # 修正：指向实际库目录
)
# 3. 链接器搜索路径
link_directories(
    ${FFMPEG_LIB_DIRS}  # 修正：使用正确的库路径变量
)
# set(RK_MPP_LIB          ${CMAKE_CURRENT_SOURCE_DIR}/rkmpp/lib/mpp/librockchip_mpp.so)
# set(RK_MPP_OSAL_LIB     ${CMAKE_CURRENT_SOURCE_DIR}/rkmpp/lib/osal/libosal.a)
# set(RK_MPP_UTILS_LIB    ${CMAKE_CURRENT_SOURCE_DIR}/rkmpp/lib/utils/libutils.a)
# set(RK_RGA_LIB          ${CMAKE_CURRENT_SOURCE_DIR}/rga/librga.so)
set(RK_MPP_LIB          ${CMAKE_CURRENT_SOURCE_DIR}/rkmpp/lib/mpp/librockchip_mpp.so)
set(RK_MPP_OSAL_LIB     ${CMAKE_CURRENT_SOURCE_DIR}/rkmpp/lib/osal/libosal.a)
set(RK_MPP_UTILS_LIB    ${CMAKE_CURRENT_SOURCE_DIR}/rkmpp/lib/utils/libutils.a)
set(RK_RGA_LIB          ${CMAKE_CURRENT_SOURCE_DIR}/rga/librga.so)
# 头文件
include_directories(
    ${CMAKE_CURRENT_LIST_DIR}/inc
    ${CMAKE_CURRENT_LIST_DIR}/rkmpp/inc
    ${CMAKE_CURRENT_LIST_DIR}/rkmpp/utils
    ${CMAKE_CURRENT_LIST_DIR}/rkmpp/osal/inc
    ${CMAKE_CURRENT_LIST_DIR}/rkmpp/osal/linux
    ${CMAKE_CURRENT_LIST_DIR}/rkmpp/mpp
    ${CMAKE_CURRENT_LIST_DIR}/rkmpp/inc
    ${CMAKE_CURRENT_LIST_DIR}/rga/inc
    ${CMAKE_CURRENT_LIST_DIR}/video
    ${CMAKE_CURRENT_LIST_DIR}/sysfs/gpio
    ${FFMPEG_INCLUDE_DIRS}  # 包含 FFmpeg 头文件
)
#添加可执行文件
set(exec main_demo)
add_executable(${exec}
        ./main.cpp
        # ./test/video/capturevideo20.cpp
        # ./test/video/test3.cpp
        # ./test/encoder/test3.cpp
        # ./test/gpio/bsp_gpio_ctl.cpp
        # ./test/uart/test_laserI_demo.cpp
        # ./test/uart/test_serial_demo.cpp
        # ./test/uart/test_imguart.cpp
        ./sysfs/gpio/gpioconfig.c
        ./video/v4l2config.c
        ./video/convert.c
        ./src/bsp_laser.cpp
        ./src/bsp_encoder.cpp
        ./src/bsp_uart.cpp
        ./src/bsp_pthread.cpp
        ./src/bsp_video.cpp
        ./src/bsp_strack.cpp
        ./src/bsp_mjpeg.cpp
        ./src/debug_log.cpp
)
# 链接库
target_link_libraries(${exec} PRIVATE
    ${RK_MPP_LIB}               # 动态库
    ${RK_MPP_OSAL_LIB}          # 静态库
    ${RK_MPP_UTILS_LIB}         # 静态库
    ${RK_RGA_LIB}

        # FFmpeg 静态库（调整顺序：libavcodec 放在 libavfilter 之后）
    ${THREERD_MODULE_FFMPEG}/lib/libavdevice.a
    ${THREERD_MODULE_FFMPEG}/lib/libavformat.a
    ${THREERD_MODULE_FFMPEG}/lib/libavfilter.a  # 先放滤镜库
    ${THREERD_MODULE_FFMPEG}/lib/libavcodec.a   # 再放编解码库（包含 DCT 功能）
    ${THREERD_MODULE_FFMPEG}/lib/libavutil.a
    ${THREERD_MODULE_FFMPEG}/lib/libswscale.a
    ${THREERD_MODULE_FFMPEG}/lib/libswresample.a
    ${THREERD_MODULE_FFMPEG}/lib/libpostproc.a

    /home/remote/project/rkmpp/lib/mpp/librockchip_mpp.a # 系统中存在的库
        # 其他依赖库（保持不变）
    xcb-shm
    xcb
    lzma
    drm
    x264
    x265
    rga

    
    m
    z
    dl
    rt

    v4l2
    pthread
    gpiod

    stdc++
)